<!--
* @description:货主管理
* @fileName: TheOwnerManagement
* @author:李周蓬
* @date:2021-1-
* @后台人员:李周蓬
-->
<template>
  <div>
    <div>
      <el-row>
        <el-col :span="3">货主姓名：</el-col>
        <el-col :span="5"
          ><el-input v-model="name" placeholder="请输入内容"></el-input
        ></el-col>
        <el-col :span="3">手机号：</el-col>
        <el-col :span="5"
          ><el-input v-model="phone" placeholder="请输入内容"></el-input
        ></el-col>
        <el-col :span="3">驾驶证有效日期：</el-col>
        <el-col :span="5"
          >
          <input type="date" v-model="time">
          </el-col>
      </el-row>
    </div>
    <div>
      <el-row>
        <el-col :span="6" class="kk">
          <el-button type="primary" @click="show">查询</el-button>
          <el-button type="primary">重置</el-button>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-button type="primary" @click="tianjia">新增</el-button>
          <el-button type="primary" @click="dels">删除</el-button>
        </el-col>
      </el-row>
    </div>
    <div>
      <el-table
        ref="multipleTable"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="OwnerName" label="货主姓名"> </el-table-column>
        <el-table-column prop="OwnerPhone" label="手机号"> </el-table-column>
        <el-table-column prop="OutsourceName" label="货主单位">
        </el-table-column>
        <el-table-column prop="OwnerAddr" label="联系地址"> </el-table-column>
        <el-table-column prop="DriverCardTimes" label="驾驶证有效日期">
        </el-table-column>
        <!-- <el-table-column label="驾驶证照片">
          <template slot-scope="scope">
            <a href="#" @click="checks(scope.row)">查看</a>
          </template>
         
        </el-table-column> -->
        <el-table-column prop="Remark" label="备注"> </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <a href="#" @click="update(scope.row)">编辑</a>
            <a href="#" @click="del(scope.row.Id)">删除</a>
            <a href="#" @click="check(scope.row)">查看</a>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageindex"
        :page-sizes="[1, 3, 5, 10]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalcount"
      >
      </el-pagination>
    </div>
    <!-- 查看货主信息 -->
    <el-dialog
      title="查看货主信息"
      :visible.sync="dialogVisible"
      width="60%"
      :before-close="handleClose"
    >
      <table>
        <tr>
          <td>货主姓名：</td>
          <td>
            <el-input
              v-model="checkData.OwnerName"
              placeholder="请输入内容"
            ></el-input>
          </td>
          <td>手机号:</td>
          <td>
            <el-input
              v-model="checkData.OwnerPhone"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>单位名称：</td>
          <td>
            <el-input
              v-model="checkData.OutsourceName"
              placeholder="请输入内容"
            ></el-input>
          </td>
          <td>联系地址:</td>
          <td>
            <el-input
              v-model="checkData.OwnerAddr"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>驾驶证有效日期：</td>
          <td>
            <el-date-picker
              v-model="checkData.DriverCardTime"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </td>
          <td>备注:</td>
          <td>
            <el-input
              v-model="checkData.Remark"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
      </table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>

    <!-- 编辑货主信息 -->
    <el-dialog
      title="编辑货主信息"
      :visible.sync="dialogVisibles"
      width="60%"
      :before-close="handleClose"
    >
      <table>
        <tr>
          <td>货主姓名：</td>
          <td>
            <el-input
              v-model="checkData.OwnerName"
              placeholder="请输入内容"
            ></el-input>
          </td>
          <td>手机号:</td>
          <td>
            <el-input
              v-model="checkData.OwnerPhone"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>单位名称：</td>
          <td>
            <el-input
              v-model="checkData.OutsourceName"
              placeholder="请输入内容"
            ></el-input>
          </td>
          <td>联系地址:</td>
          <td>
            <el-input
              v-model="checkData.OwnerAddr"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
        <tr>
          <td>驾驶证有效日期：</td>
          <td>
            <el-date-picker
              v-model="checkData.DriverCardTime"
              type="date"
              placeholder="选择日期"
            >
            </el-date-picker>
          </td>
          <td>备注:</td>
          <td>
            <el-input
              v-model="checkData.Remark"
              placeholder="请输入内容"
            ></el-input>
          </td>
        </tr>
      </table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibles = false">取 消</el-button>
        <el-button type="primary" @click="xiu">修 改</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="提示"
      :visible.sync="dialogVisiblek"
      width="30%"
      :before-close="handleClose"
    >
     <img :src="showxian" width="80px" height="80px"/>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisiblek = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisiblek = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      imageUrl: "",
      tableData: [],
      name: "",
      phone: "",
      time: "",
      pageindex: 1,
      pagesize: 3,
      totalcount: 0,
      ids: [],
      dialogVisible: false,
      dialogVisibles: false,
      dialogVisiblek: false,
      checkData: {
        Id: "",
        OwnerNumber: "",
        OwnerName: "",
        OwnerPhone: "",
        OwnerAddr: "",
        DriverCardTime: "",
        CardImg: "",
        Remark: "",
        IsDelete: "",
        OutsourceId: "",
      },
      showxian:"",
    };
  },
  methods: {
    handleSizeChange(val) {
      this.pagesize = val;
      this.show();
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.pageindex = val;
      this.show();
      console.log(`当前页: ${val}`);
    },
    handleClose(done) {
      this.$confirm("确认关闭？").then(() => {
        done();
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.ids = [];
      for (var i = 0; i < val.length; i++) {
        this.ids.push(val[i].Id);
      }
    },
    show() {
      this.$axios
        .get("https://localhost:44399/api/app/owner/show-owner", {
          params: {
            name: this.name,
            phone: this.phone,
            time: this.time,
            pageindex: this.pageindex,
            pagesize: this.pagesize,
          },
        })
        .then((res) => {
          this.tableData = res.data.PageData;
          this.totalcount = res.data.PageTotal;
          console.log(this.tableData);
        });
    },
    update(row) {
      this.checkData = null;
      this.dialogVisibles = true;
      this.checkData = row;
    },
    //删除
    del(Id) {
      if (confirm("确定删除吗？")) {
        //https://localhost:44399/api/app/owner/1/del-car
        this.$axios
          .delete("https://localhost:44399/api/app/owner/" + Id + "/del-owner")
          .then((res) => {
            if (res.data > 0) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.show();
            } else {
              this.$message({
                type: "error",
                message: "删除失败!",
              });
            }
          });
      }
    },
    check(row) {
      this.checkData = null;
      this.dialogVisible = true;
      this.checkData = row;
    },
    checks(row) {
      this.dialogVisiblek = true;
      this.showxian ="http://localhost:44399/api/wenjianweiz/"+row.CardImg;
      console.log(this.showxian);
    },
    tianjia() {
      this.$router.push("/TheNewOwnerOfTheGoods");
    },
    //批量删除
    dels() {
      if (confirm("确定删除吗？")) {
        this.$axios
          .delete(
            "https://localhost:44399/api/app/owner/dels-owner?ids=" + this.ids
          )
          .then((res) => {
            if (res.data > 0) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.show();
            } else {
              this.$message({
                type: "error",
                message: "删除失败!",
              });
            }
          });
      }
    },
    xiu() {
      this.$axios
        .put(
          "https://localhost:44399/api/app/owner/update-owner",
          this.checkData
        )
        .then((res) => {
          if (res.data > 0) {
            this.$message({
              type: "success",
              message: "修改成功!",
            });
            this.dialogVisibles = false;
            this.show();
          } else {
            this.$message({
              type: "error",
              message: "修改失败!",
            });
          }
        });
    },
  },
  created() {
    this.show();
  },
};
</script>


<style scoped>
.kk {
  margin-top: 20px;
  float: right;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>